{% extends "base.html" %}

{% block extrahead %}
<link rel="stylesheet" href="/appmedia/item.css" />

<script language="JavaScript" type="text/javascript">
	
	//---------------------------------------------------------------------
    // 
    function ChangeNumber(delta, id) {
		var val = $("#"+id).val();
		if (val=="") {
			var num = 0.0 + delta;
		}
		else {
			var num = parseFloat(val) + delta;
		}
		if (num < 0.0) { num=0; }
		$("#"+id).val(num.toFixed(2));
	}
	
	//---------------------------------------------------------------------
    // 
    function SaveAndStayHere() {
    	var item_form = document.getElementById('new_item');
    	var save_and_stay = document.getElementById('save_and_stay');
    	save_and_stay.value = 'yes';
    	item_form.target = 'our_hidden_frame';
    	item_form.submit();
    	item_form.target = '';
    	save_and_stay.value = 'no';
    }
    
	//---------------------------------------------------------------------
    // 
    $(function() {
    	$("input.vFloatField").each(function(){
    		if($(this).val()=="") {$(this).val(0);}
    		$(this).after('<a href="javascript:ChangeNumber(-0.5, ' + "'" + this.id + "'" +')">-0.5</a>');
    		$(this).after(' <a href="javascript:ChangeNumber(0.5, ' + "'" + this.id + "'" +')">+0.5</a> / ');
    		
    	});
    });

</script>
{% endblock %}

{% block content %}
	<div class="form_layer">
		<h1>Edit {{model_name|lower}}</h1>
	
		<form id="new_item" method="post" action="">
			<table id="Task" cellspacing="0">
				{{form}}
				<input id="save_and_stay" name="save_and_stay" type="hidden" value="">
			<tr>
				<th style="border-right:0px none;border-left:0px none;background-color:white;">&nbsp;</th>
				<td style="border-right:0px none;border-left:0px none;background-color:white;">&nbsp;</td>
			</tr>
			</table>
			<p>
			<a class="button" href="javascript:document.getElementById('new_item').submit()"> Save {{model_name|lower}} </a>
			<a class="button" href="javascript:SaveAndStayHere()"> Save and continue editing </a>
			<a class="button" href="/{{model_name|lower}}s/"> Return to list </a>
			{% if item.deleted %}
			<a class="button" href="/{{model_name|lower}}/unarchive/{{item.id}}/"> Unarchive {{model_name|lower}} </a>
			{% endif %}
		</form>
	</div>
	
	<iframe id="our_hidden_frame" name="our_hidden_frame" style="display:none;">
	
	</iframe>
	
	<script type="text/javascript">document.getElementById("id_name").focus();</script>

{% endblock %}

{% block analytics %}
	<!-- We don't need to give Google this content. Analytics is of. -->
{% endblock %}